package view;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import Dub.DubProveedor;
import controler.SistemaIndumentaria;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ModificarProveedor extends javax.swing.JFrame {
	private static final long serialVersionUID = 1L;

	private static ModificarProveedor instModificarProveedor;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	
	private JTextField jTextcuit;
	private JButton jBBuscar;
	private JLabel jLalerta;
	private JButton jBCancelar;
	private JButton jBAceptar;
	private JTextField jTextdireccion;
	private JTextField jTextrazonSocial;
	private JTextField jTextidProveedor;
	private JTextField jTexttelefono;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		ModificarProveedor inst = new ModificarProveedor();
		inst.setVisible(true);
	}
	
	private ModificarProveedor() {
		super();
		initGUI();
	}
	
	public static ModificarProveedor getInstance(boolean init)
	{
		if (instModificarProveedor==null)
		{
			instModificarProveedor= new ModificarProveedor();
			
		}
		if (init)
		{
			instModificarProveedor.inicializarPantalla();
		}
		return instModificarProveedor;
		
	}
	
	
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Modificar Proveedor");
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("ID PROVEEDOR");
				jLabel1.setBounds(49, 21, 63, 21);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("CUIT");
				jLabel2.setBounds(49, 52, 63, 28);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("DIRECCION");
				jLabel3.setBounds(49, 84, 63, 28);
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setText("RAZON SOCIAL");
				jLabel4.setBounds(49, 108, 63, 28);
			}
			{
				jLabel5 = new JLabel();
				getContentPane().add(jLabel5);
				jLabel5.setText("TELEFONO");
				jLabel5.setBounds(49, 128, 63, 28);
			}
			{
				jTextidProveedor = new JTextField();
				getContentPane().add(jTextidProveedor);
				jTextidProveedor.setBounds(112, 21, 70, 21);
			}
			{
				jTextcuit = new JTextField();
				getContentPane().add(jTextcuit);
				jTextcuit.setBounds(112, 56, 224, 21);
			}
			{
				jTextdireccion = new JTextField();
				getContentPane().add(jTextdireccion);
				jTextdireccion.setBounds(112, 84, 224, 21);
			}
			
			{
				jTextrazonSocial = new JTextField();
				getContentPane().add(jTextrazonSocial);
				jTextrazonSocial.setBounds(112, 108, 224, 21);
			}
			{
				jTexttelefono = new JTextField();
				getContentPane().add(jTexttelefono);
				jTexttelefono.setBounds(112, 128, 224, 21);
			}
			{
				jBAceptar = new JButton();
				getContentPane().add(jBAceptar);
				jBAceptar.setText("ACEPTAR");
				jBAceptar.setBounds(49, 203, 110, 28);
				jBAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jBAceptar.actionPerformed, event="
								+ evt);
						SistemaIndumentaria.getInstancia().modificarProveedor(Integer.parseInt(jTextidProveedor.getText()),jTextcuit.getText(), jTextdireccion.getText(), jTexttelefono.getText(),jTextrazonSocial.getText());
					}
				});
			}
			{
				jBCancelar = new JButton();
				getContentPane().add(jBCancelar);
				jBCancelar.setText("CANCELAR");
				jBCancelar.setBounds(224, 203, 110, 28);
				jBCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jBCancelar.actionPerformed, event="
							+ evt);
						ModificarProveedor.getInstance(true).setVisible(false);
					}
				});
			}
			{
				jBBuscar = new JButton();
				getContentPane().add(jBBuscar);
				jBBuscar.setText("BUSCAR");
				jBBuscar.setBounds(210, 21, 119, 21);
				jBBuscar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jBBuscar.actionPerformed, event="+evt);
						DubProveedor dubm = null; 
						dubm = SistemaIndumentaria.getInstancia().buscarDubProveedor(Integer.parseInt(jTextidProveedor.getText()));
						if (dubm == null)
						   {
							jLalerta.setForeground(Color.RED);
							jLalerta.setText("EL Proveedor no existe");
						   }
						else
							{
							 jTextcuit.setText(dubm.getCuit());
							 jTextdireccion.setText(dubm.getDireccion());
							 jTextrazonSocial.setText(dubm.getRazonSocial());
							 jTexttelefono.setText(dubm.getTelefono());
							}				
					}
				});
			}
			{
				jLalerta = new JLabel();
				getContentPane().add(jLalerta);
				jLalerta.setBounds(49, 124, 287, 19);
			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void inicializarPantalla()
	{
	
		//this.txtDni.setText("");
		//this.txtNombre.setText("");
		//this.txtcuit.setText("");
		//this.txtDireccion.setText("");
		//this.txtTelParticular.setText("");
		//this.txtFechaIngreso.setText("");
		//this.txtFechaNacimiento.setText("");
		//this.cargarTabla();
	}
	
	
	
}
